#coding=utf-8
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.utils.deprecation import MiddlewareMixin
from django.conf import settings

class UserAuthMiddle(MiddlewareMixin):
    def process_request(self, request):
        url_path = request.path
        if url_path.startswith(settings.LOGIN_URL):
            return
        elif request.user.is_authenticated:
            return
        else:
            return HttpResponseRedirect(reverse('login'))